# CMake 最低版本要求
cmake_minimum_required(VERSION 3.10)

# 项目名称
project(c-core)

# 设置C标准
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)

# 头文件目录
include_directories(${CMAKE_SOURCE_DIR}/src/include)

# 主程序源文件（不包含main.c，单独处理）
file(GLOB MAIN_SOURCES "src/main/*.c")
list(FILTER MAIN_SOURCES EXCLUDE REGEX ".*main\.c$")

# 测试源文件
file(GLOB TEST_SOURCES "src/test/*.c")

# 主程序（包含主main.c）
add_executable(c-core ${MAIN_SOURCES} "src/main/main.c")

# 如果有测试文件，添加测试程序
if(TEST_SOURCES)
    add_executable(run_tests ${MAIN_SOURCES} ${TEST_SOURCES})
endif()

# 设置输出目录
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)

# 安装配置
install(TARGETS c-core DESTINATION bin)
if(TEST_SOURCES)
    install(TARGETS run_tests DESTINATION bin)
endif()

# 打印构建信息
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "C Compiler: ${CMAKE_C_COMPILER}")
message(STATUS "Source directory: ${CMAKE_SOURCE_DIR}")
message(STATUS "Binary directory: ${CMAKE_BINARY_DIR}")